package com.example.lynandroid.activity

import android.os.Bundle
import android.view.KeyEvent
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.commit
import com.example.lynandroid.*
import com.example.lynandroid.databinding.ContainBinding
import com.example.lynandroid.fragment.*

class ContainActivity : FragmentActivity() {
    private lateinit var binding: ContainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ContainBinding.inflate(layoutInflater).apply {
            setContentView(root)
            intent?.getStringExtra(KEY_FRAGMENT_CLASS)?.let {
                supportFragmentManager.commit {
                    setReorderingAllowed(true)
                    add(R.id.fragment, getFragment(it))
                }
            }
        }

    }

    private fun getFragment(key: String): Fragment {
        return when (key) {
            FRAGMENT_INPUT -> InputFragment()
            FRAGMENT_PATCH9 -> Patch9Fragment()
            FRAGMENT_VIEW -> MyViewFragment()
            FRAGMENT_WINDOW -> WindowFragment()
            FRAGMENT_EDIT -> EditFragment()
            else -> Fragment()
        }
    }
}